using System.Globalization;
using System.Windows.Data;

namespace DimensionsHelper.Client.Converters;

public class NullToVisibilityConverter : IValueConverter
{
    public static NullToVisibilityConverter Instance => new();


    public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        if (value is string str)
        {
            return string.IsNullOrEmpty(str) ? Visibility.Collapsed : Visibility.Visible;
        }

        return value is null ? Visibility.Collapsed : Visibility.Visible;
    }

    public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        return Binding.DoNothing;
    }
}